#!/usr/bin/env python
# -*- coding: utf-8 -*-

#    Copyright (C) 2014 by Promotux
#                        di Francesco Meloni snc - http://www.promotux.it/

#    Author: Francesco Meloni  <francesco@promotux.it>

#    This file is part of Odcollect.

#    OdCollect is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 2 of the License, or
#    (at your option) any later version.

#    OdCollect is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with OdCollect.  If not, see <http://www.gnu.org/licenses/>.

import sys
from imp import reload
import sys; reload(sys).setdefaultencoding('utf-8')
import os
path =  os.path.expanduser('~') + '/odmc/'

from werkzeug import run_simple
import preEnv
from lib.config import Config
preEnv.web = True
main_conf = Config(os.path.join('pgweb.conf'))
preEnv.main_conf_force = main_conf
import Environment  # non toccare
from werkzeug.debug import DebuggedApplication

feedTrac = None
feedPromo = None
orario = 0
SUB = ""

def make_app():
    """ """
    from PgWeb import PgWebGeneric
    application = DebuggedApplication(PgWebGeneric(path=path), evalex=True)
    #application = PgWebGeneric()
    return application

app = make_app()
from werkzeug.contrib.profiler import ProfilerMiddleware
#app = ProfilerMiddleware(app)
if __name__ == '__main__':
    hostname = main_conf.Server.hostname
    run_simple(hostname=hostname,
                port=int(main_conf.Server.port),
                application=app,
                threaded=True,
                #processes = 100,
                use_reloader=True,
                extra_files=["pgweb.conf"]
                )
